package com.yike.user.controller;

import com.yike.user.entity.AgentCommission;
import com.yike.user.service.AgentCommissionService;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.AgentCommissionPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 代理商分佣表 控制器
 *
 * @author Sakura
 * @since 2024-09-09
 */
@Slf4j
@RestController
@RequestMapping("/agentCommission")
@Module("user")
@Api(value = "代理商分佣表API", tags = {"代理商分佣表"})
@ApiIgnore
public class AgentCommissionController extends BaseController {

    @Autowired
    private AgentCommissionService agentCommissionService;

    /**
     * 添加代理商分佣表
     */
    @PostMapping("/add")
    @OperationLog(name = "添加代理商分佣表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加代理商分佣表", response = ApiResult.class)
    public ApiResult<Boolean> addAgentCommission(@Validated(Add.class) @RequestBody AgentCommission agentCommission) throws Exception {
        boolean flag = agentCommissionService.saveAgentCommission(agentCommission);
        return ApiResult.result(flag);
    }

    /**
     * 修改代理商分佣表
     */
    @PostMapping("/update")
    @OperationLog(name = "修改代理商分佣表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改代理商分佣表", response = ApiResult.class)
    public ApiResult<Boolean> updateAgentCommission(@Validated(Update.class) @RequestBody AgentCommission agentCommission) throws Exception {
        boolean flag = agentCommissionService.updateAgentCommission(agentCommission);
        return ApiResult.result(flag);
    }

    /**
     * 删除代理商分佣表
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除代理商分佣表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除代理商分佣表", response = ApiResult.class)
    public ApiResult<Boolean> deleteAgentCommission(@PathVariable("id") Long id) throws Exception {
        boolean flag = agentCommissionService.deleteAgentCommission(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取代理商分佣表详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "代理商分佣表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "代理商分佣表详情", response = AgentCommission.class)
    public ApiResult<AgentCommission> getAgentCommission(@PathVariable("id") Long id) throws Exception {
        AgentCommission agentCommission = agentCommissionService.getById(id);
        return ApiResult.ok(agentCommission);
    }

    /**
     * 代理商分佣表分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "代理商分佣表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "代理商分佣表分页列表", response = AgentCommission.class)
    public ApiResult<Paging<AgentCommission>> getAgentCommissionPageList(@Validated @RequestBody AgentCommissionPageParam agentCommissionPageParam) throws Exception {
        Paging<AgentCommission> paging = agentCommissionService.getAgentCommissionPageList(agentCommissionPageParam);
        return ApiResult.ok(paging);
    }

}

